package com.efuture.vdrp.android.bo;

import java.math.BigDecimal;
import java.sql.Connection;
import java.util.Vector;

import com.efuture.vdrp.android.bean.AndroidDevelopBean;



public class AndroidDevelopBOImp implements AndroidDevelopBO {
	public java.lang.Object[] loadLeave(java.sql.Connection connection, AndroidDevelopBean bean)
    throws Exception {

	Object obj[] = null;
	boolean independenceTransactionFlag = false;
	try {
		if (connection == null) {
			//connection = getConnection();
			//setTransactionBegin(connection, LOAD);
			independenceTransactionFlag = true;
		}
		String strSQL = "select a.*,b.Org_num,b.Org_name,b.Org_type,b.Only_path,c.Customer_num,c.Customer_name,c.Customer_use_credit,c.Execute_price_id, "
					+ " d.Salesperson_num,d.Salesperson_name,d.Least_discount, "
					+ " e.Inventory_num,e.Inventory_name,e.warehouse_type_num,f.PHONE_NUM,f.Address_name_line1 as ship_to_site_name,"
					+ " f.First_name as ship_to_site_linkman, "
					+ " g.Address_name_line1 as Invoice_to_site_name,g.First_name as Invoice_to_site_linkman,"
					+ " i.User_code as Audit_num,i.User_name as Audit_name,j.User_code as Created_num,j.User_name as Created_name, "
					+ " l.User_code as Cancel_num,l.User_name as Cancel_name,"
					//+ " m.So_out_bill_address_num,m.comments as So_out_bill_address_name,  "
					+ " n.Org_num as Dc_org_num,n.Org_name as Dc_org_name,"
					//+ " t3.org_num as Period_org_num,t3.org_name as Period_org_name, "
					//+ " (case when t2.bank_account_num is not null then t2.bank_account_num else c.bank_account_num end) as bank_account_num ,"
					//+ " (case when t2.tax_registration_num is not null then t2.tax_registration_num else c.tax_registration_num end) as tax_registration_num,"
					//+ " t2.Customer_store_num,t2.Customer_store_name, t5.WORK_TYPE, "
					+ " t4.stockman_num,t4.comments as stockman_name"
					+ " from SO_SALE_HEADERS a "
					+ " Left outer join OR_ORGANIZATIONS b ON b.org_id = a.Org_id "
					+ " Left Outer join SO_CUSTOMERS c ON c.Customer_id = a.Customer_id "
					+ " Left Outer join SO_SALESPERSON d ON d.Salesperson_id = a.Salesperson_id "
					+ " Left Outer join OR_INVENTORIES e ON e.Inventory_id = a.Inventory_id "
					+ " Left Outer join SO_CUSTOMER_SITES_ALL f ON f.Customer_site_id = a.Ship_to_site_id "
					+ " Left Outer join SO_CUSTOMER_SITES_ALL g ON g.Customer_site_id = a.Invoice_to_site_id "
					+ " Left Outer join SM_USER i ON i.User_id = a.Audit_by "
					+ " Left Outer join SM_User j On j.User_id_str = a.Created_by "
//					+ " Left Outer join SO_ORG_CUSTOMER_DISCOUNT k ON k.Org_id = a.Org_id and k.Customer_id = a.Customer_id "
					+ " Left Outer join SM_USER l On l.User_id = a.Cancel_by "
//					+ " Left Outer join CO_SO_OUT_BILL_ADDRESS m On m.so_out_bill_address_id = a.so_out_bill_address_id "
					+ " Left Outer join OR_ORGANIZATIONS n On n.Org_id = a.Dc_org_id "
//					+ " Left outer join co_manufactory_promotion o on o.manufactory_promotion_id = a.manufactory_promotion_id "
//					+ " Left outer join SO_BRAND_DISCOUNT p on p.customer_item_discount_id = a.customer_item_discount_id "
//					+ " left outer join or_organizations t3 on length(b.full_path)-POSSTR(b.full_path,'|')<>0 and SUBstr(b.full_path,POSSTR(b.full_path,'|')+1,posstr(SUBstr(b.full_path,POSSTR(b.full_path,'|')+1,length(b.full_path)-POSSTR(b.full_path,'|')),'|')-1)=t3.org_num"
					+ " Left outer join co_stockman t4 on t4.stockman_id = a.stockman_id "
//					+ " left outer join SO_CUSTOMER_STORE t2 on t2.SO_CUSTOMER_STORE_ID = a.Customer_store_id "
//					+ " left outer join SO_CUST_CONTRACT_HEADERS t5 on t5.CUST_CONTRACT_HEADERS_ID = a.CONTRACT_HEADERS_ID "
//					+ " left outer join ar_payee t8 on a.payee_id = t8.payee_id "
					+ " where sale_header_id =1=1";
			//obj = findBySql(connection, bean, strSQL);

		for (int i = 0; i < obj.length; i++) {
			strSQL = " select b.Valid_dates,b.item_num,b.item_name,b.define_content,b.sale_price_t4,b.item_short_name,b.vendor_item_code,(a.line_index+1) as line_index,a.*,b.Single_uom,b.Single_contents,b.Inner_uom,b.Inner_contents,"
					+ " b.Outer_uom,b.Outer_contents,b.Brand_id,b.Sale_price_t1,b.Sale_price_t2,b.Sale_price_t3,b.Sale_price_t4,a.order_uom,a.order_contents,  "
					+ " b.SINGLE_BAR_CODE,b.min_sale_price,b.outer_bar_code,b.min_sale_price_t,b.Sale_price_t4*a.Min_uom_quantity as tc_sale_price_t4, "
					//+ " c.Limit_quantity_forever,c.Limit_quantity_flag,c.Sales_promotion_max_quantity - c.sales_promotion_use_quantity as Promotion_remain_quantity, "
					+ " coalesce(b.single_weight,0)*coalesce(a.min_uom_quantity,0) as line_weight,b.locator_flag, d.ITEM_CLASS_NUM,d.ITEM_CLASS_NAME, "
					+ " (case when a.user_define_contents is null then 0 when a.user_define_contents = 0 then 0 else round(coalesce(a.min_uom_quantity,0),10)/round(coalesce(a.user_define_contents,1),8) end ) as user_define_outer_quantity,"
					+ " b.manufactory_item_code"
					+ " from SO_SALE_LINES a "
					+ " Left Outer join GD_ITEMS b ON b.Item_id = a.Item_id "
					+ " left outer join CO_ITEM_CLASS d on d.ITEM_CLASS_ID = b.CATEGORY_ID"
					//+ " Left Outer join SO_ORG_CUSTOMER_ITEM_DISCOUNT c On c.AUTO_CX_NUM = a.ORG_CUSTOMER_DISCOUNT_NUM "
					//+ " and c.item_id = a.Item_id "
					+ " where  1=1";
//			try {
//				Object[] lineObj = findBySql(connection, lineBean, strSQL);
//				((SoSaleHeadersBean) obj[i]).setLineVector(ConversionUtils.convertArrayToVector(lineObj));

//			} catch (DataNotFoundException d) {
//			}
		}
		//setTransactionCommit(connection, independenceTransactionFlag);
	}  finally {
		//closeConnection(connection, independenceTransactionFlag);
	}
	return obj;
  }
}
